Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
:cake: 不到1k, 一个mini的事件管理器, 希望能在您的代码中做一块砖.
npm i -S any-event
import EventEmitter from 'any-event';
const emitter = new EventEmitter();
emitter.on('add', data=>{
console.log(data) // 1
});
emitter.emit('add', 1);
绑定事件
名称 | 类型 | 数据类型 | 是否必填 | 说明 |
---|---|---|---|---|
eventName | 参数 | String/Symbol | 是 | 事件名称 |
listener | 参数 | Function | 是 | 对应的回调函数 |
emitter | 返回值 | EventEmitter | --- | 实例 |
解除绑定, 如果不填写listener
, 那么eventName
对应的listener
都会被移除.
名称 | 类型 | 数据类型 | 是否必填 | 说明 |
---|---|---|---|---|
eventName | 参数 | String/Symbol | 是 | 事件名称 |
listener | 参数 | Function | 是 | 对应的回调函数 |
emitter | 返回值 | EventEmitter | --- | 实例 |
const callback = data=>{
alert(data)
};
emitter.on('add', callback);
// 解除绑定
emitter.off('add', callback);
// add事件不会触发
emitter.emit('add', 1);
绑定事件, 只触发一次
名称 | 类型 | 数据类型 | 是否必填 | 说明 |
---|---|---|---|---|
eventName | 参数 | String/Symbol | 是 | 事件名称 |
listener | 参数 | Function | 是 | 对应的回调函数 |
emitter | 返回值 | EventEmitter | --- | 实例 |
const callback = data=>{
alert(data)
};
emitter.once('add', callback);
// add事件触发
emitter.emit('add', 1);
// add事件不会触发
emitter.emit('add', 1);
触发事件, 支持任意数量参数
名称 | 类型 | 数据类型 | 是否必填 | 说明 |
---|---|---|---|---|
eventName | 参数 | String/Symbol | 是 | 事件名称 |
...args | 参数 | Any | 是 | 对应的回调函数 |
emitter | 返回值 | Boolean | --- | 实例 |
const callback = (a,b,c,d)=>{
console(a,b,c,d); // 1,2,3,4
};
emitter.once('add', callback);
// add事件触发
emitter.emit('add', 1,2,3,4);
是否绑定了指定事件
名称 | 类型 | 数据类型 | 是否必填 | 说明 |
---|---|---|---|---|
eventName | 参数 | String/Symbol | 是 | 事件名称 |
emitter.on('add', callback);
emitter.has('add'; // true
销毁实例
const callback = (a,b,c,d)=>{
console(a,b,c,d); // 1,2,3,4
};
emitter.once('add', callback);
emitter.destroy();
// add事件不会触发
emitter.emit('add', 1,2,3,4);
FAQs
The npm package any-event receives a total of 1,520 weekly downloads. As such, any-event popularity was classified as popular.
We found that any-event demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.